class SessionsController < Clearance::SessionsController

  def new
  	respond_to do |format|
  		format.js
  	end
  end

  def create
    @user = authenticate(params)
    if @user.nil?
		  respond_to do |format|
			 format.js { render 'sessions/create_error'}
		  end
	  else
	  
  		sign_in(@user)
  		
  		@subscriptions = @user.subscription
  			
        @markers = Array.new
  
        current_user.subscription.to_gmaps4rails do |subscription, marker|
            @weather = Weather.get_weather(subscription.city)
    
             @markers.push({  
                   description: render_to_string(:partial => 'weathers/show'),
                   lng: @weather['location']['longitude'], 
                   lat: @weather['location']['latitude'], 
                   picture: @weather['forecast']['now']['icon'], 
                   width: "30", 
                   height: "30",
                   rich_marker: render_to_string(:partial => "/weathers/now_on_map"),
                   title: @weather['location']['city']
               })
        end 
      
  		respond_to do |format|
  			format.js { render 'sessions/create' }
  		end
	 end
  end

  def destroy
    sign_out
	redirect_to root_url
  end
  
    private


  def url_after_create
    root_url
  end

  def url_after_destroy
    root_url
  end  

end
